package com.yike.order.service.impl;

import com.yike.order.entity.Refund;
import com.yike.order.mapper.RefundMapper;
import com.yike.order.service.RefundService;
import com.yike.order.param.RefundPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yike.common.base.BaseServiceImpl;
import com.yike.common.pagination.Paging;
import com.yike.common.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;

/**
 * 退款单表 服务实现类
 *
 * @author yike
 * @since 2024-08-01
 */
@Slf4j
@Service
public class RefundServiceImpl extends BaseServiceImpl<RefundMapper, Refund> implements RefundService {

    @Resource
    private RefundMapper refundMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveRefund(Refund refund) throws Exception {
        return super.save(refund);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateRefund(Refund refund) {
        return super.updateById(refund);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteRefund(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<Refund> getRefundPageList(RefundPageParam refundPageParam) throws Exception {
        Page<Refund> page = new PageInfo<>(refundPageParam, OrderItem.desc(getLambdaColumn(Refund::getCreateTime)));
        LambdaQueryWrapper<Refund> wrapper = new LambdaQueryWrapper<>();
        IPage<Refund> iPage = refundMapper.selectPage(page, wrapper);
        return new Paging<Refund>(iPage);
    }

}
